import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    count: 0,
    car:[]
  },
  mutations: {
    // 将最新的商品数量进行赋值
    count(state, newInputValue) {
      state.count = newInputValue
    },
    // 购物车数组
    addCart(state,car) {
      state.car = car
    },
    // 删除对应的数据
    removeCart(state,id){
      const index = state.car.findIndex(v=>v.id===id)
      state.car.splice(index,1)
    }
  },
  actions: {

  }
})